describe("api_user in SG", function() {
    beforeEach(function() {
        App.initSession();
    });

    describe("_processLogin", function() {

        it("login success and two FA type is SMS", function() {
            var response = {
                loginResponse: {
                    login: {
                        sessionId: "D6FE4FCEDABED8D9F2DF",
                        securityCode: "1972b97b35f0a90107e43942a25d400d",
                        customerName1: "XXXX",
                        lastLoginDate: "2013-03-13T11:11:05.529+0800"
                    },
                    isALPRequired: true,
                    responseHeader: {
                        "status": 1,
                        "nonce": "ec562d26a1e33aa34cd42105ab75fb5b",
                        "currentTimestamp": "2013-03-13T11:12:01.675+0800"
                    }
                }
            }
            var callback = jasmine.createSpy();
            App.api_user.callbackLogin = callback;

            App.api_user._processLogin(response);

            expect(App.getSession().getBreezeContext().userContext.sessionId).toBe(response.loginResponse.login.sessionId);
            expect(App.getSession()._securityCode).toBe(response.loginResponse.login.securityCode);
            expect(App.getSession().getChallengeOpaque()).toBe(null);
            expect(App.getSession().getSeedValue()).toBe(null);
            expect(App.getSession().getAttribute('user').get('isSMSToken')).toBeTruthy();
        });

        it("login success and two FA type is MAS", function() {
            var response = {
                loginResponse: {
                    login: {
                        sessionId: "D6FE4FCEDABED8D9F2DF",
                        securityCode: "1972b97b35f0a90107e43942a25d400d",
                        customerName1: "XXXX",
                        lastLoginDate: "2013-03-13T11:11:05.529+0800"
                    },
                    isALPRequired: true,
                    responseHeader: {
                        "status": 1,
                        "nonce": "ec562d26a1e33aa34cd42105ab75fb5b",
                        "currentTimestamp": "2013-03-13T11:12:01.675+0800"
                    },
                    twoFA: {
                        seedValue: "5705",
                        challenge: "559"
                    }
                }
            }
            var callback = jasmine.createSpy();
            App.api_user.callbackLogin = callback;

            App.api_user._processLogin(response);

            expect(App.getSession().getBreezeContext().userContext.sessionId).toBe(response.loginResponse.login.sessionId);
            expect(App.getSession()._securityCode).toBe(response.loginResponse.login.securityCode);
            expect(App.getSession().getChallengeOpaque()).toBe(response.loginResponse.twoFA.challenge);
            expect(App.getSession().getSeedValue()).toBe(response.loginResponse.twoFA.seedValue);
            expect(App.getSession().getAttribute('user').get('isSMSToken')).toBeFalsy();
        });

        it("login success and need not ALP", function() {
            var response = {
                loginResponse: {
                    login: {
                        sessionId: "D6FE4FCEDABED8D9F2DF",
                        securityCode: "1972b97b35f0a90107e43942a25d400d",
                        customerName1: "XXXX",
                        lastLoginDate: "2013-03-13T11:11:05.529+0800"
                    },
                    isALPRequired: false,
                    responseHeader: {
                        "status": 1,
                        "nonce": "ec562d26a1e33aa34cd42105ab75fb5b",
                        "currentTimestamp": "2013-03-13T11:12:01.675+0800"
                    }
                }
            }
            var callback = jasmine.createSpy();
            App.api_user.callbackLogin = callback;

            App.api_user._processLogin(response);

            expect(App.getSession().getBreezeContext().userContext.sessionId).toBe(response.loginResponse.login.sessionId);
            expect(App.getSession()._securityCode).toBe(response.loginResponse.login.securityCode);
            expect(App.getSession().getAttribute('user').get('isValidated')).toBeTruthy();
        });
        
        it("login error", function() {
            var response = {
                loginResponse: {
                    responseHeader: {
                        "status": 0,
                        "nonce": "ec562d26a1e33aa34cd42105ab75fb5b",
                        "currentTimestamp": "2013-03-13T11:12:01.675+0800"
                    }
                }
            }
            var callback = jasmine.createSpy();
            App.api_user.callbackLogin = callback;

            App.api_user._processLogin(response);

            expect(App.api_user.callbackLogin).toHaveBeenCalled();
        });

    });

});